package com.tdwyz.fictionmanage.mapper;

import com.tdwyz.fictionmanage.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username}")
    User selectByUsername(String username);

    /**
     * 新增用户
     * @param username
     * @param password
     * @param salt
     * @return
     */
    @Insert("insert into user(username,password,create_time,update_time,salt)" +
            "values (#{username},#{password},now(),now(),#{salt})")
    int add(String username, String password,String salt);

    @Select("select * from user where username=#{username}")
    User findUserByName(String username);

    @Update("update user set nickname=#{nickname},email=#{email},update_time=now() where id=#{id}")
    int update(User user);

    @Update("update user set user_pic=#{avatarUrl},update_time=now() where username=#{username}")
    int updateAvatar(String username, String avatarUrl);

    @Update("update user set password=#{newPwd},update_time=now() where username=#{username}")
    int updatePwd(String newPwd, String username);
}
